<?php

class Core_Backend_Component_Subject_Controller_Concessions extends Dcmp_Component_Controller {

    public function indexAction($id,$pageindex = 1, $pagesize = 20, $sort = 'modifiedtime', $dir = 'desc') {
        $this->getHistory()->record();
        $validator = $this->getRequest()->getValidator('filter');
        $subject = App::getModel('subject/content')->load($id);
        $collection = $subject   ->getConcessions()
                                 ->sortBy($sort, $dir)
                                 ->load();
        $this->getSession()->set('current_subject_id',$id);
        return $this->viewResult(array('list' => $collection,'subject'=>$subject));
    }

    public function previewAction($id) {
        $concessions = App::getModel('promotion/concessions')->load($id);
        return $this->viewResult(array('concessions' => $concessions));
    }

    public function reviewAction($status,$ids) {
        $subject = App::getModel('subject/content')->load($this->getSession()->get('current_subject_id'));
        $subject ->penndingConcessionsRelation($status,$ids);
        return $this->redirectResult($this->getUrl(array('id'=>$this->getSession()->get('current_subject_id')),'index','concessions','subject'));
    }

    public function deleteConcessionsAction($ids) {
        $subject = App::getModel('subject/content')->load($this->getSession()->get('current_subject_id'));
        $subject ->deleteConcessionsRelation($ids);
        return $this->redirectResult($this->getUrl(array('id'=>$this->getSession()->get('current_subject_id')),'index','concessions','subject'));
    }

}